#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
void solve();
int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T = 1;
    std::cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}
int dp[101][101][101];
void check_max(int &a, int b)
{
    if (a < b)
    {
        a = b;
    }
}
void solve()
{
    memset(dp, -1, sizeof(dp));
    dp[0][0][0] = 0;
    int n;
    cin >> n;
    std::vector<int> a(1);
    for (int i = 1; i <= n; ++i)
    {
        int x;
        cin >> x;
        a.push_back(x);
    }
    if (n > 100) {
        cout << 0 << endl;
        return ;
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int x1 = 0; x1 <= 100; ++x1)
        {
            for (int x2 = 0; x2 <= 100; ++x2)
            {
                if (dp[i - 1][x1][x2] == -1)
                {
                    continue;
                }
                check_max(dp[i][a[i]][x2], dp[i - 1][x1][x2] + ((a[i] == x1) ? x1 : 0));
                check_max(dp[i][x1][a[i]], dp[i - 1][x1][x2] + ((a[i] == x2) ? x2 : 0));
            }
        }
    }
    int res = 0;
    for (int x1 = 1; x1 <= 100; ++x1)
    {
        for (int x2 = 1; x2 <= 100; ++x2)
        {
            check_max(res, dp[n][x1][x2]);
        }
    }
    cout << res << endl;
    return;
}
/* 35pts
    Stats:
    SAMPLE       TIME   MEMORY
    color1.in   0.00s   7.464M
    color2.in   ======WA======
*/